<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="theme-color" content="#ff4004"><meta name="author" content="baiyun"><meta name="copyright" content="baiyun"><meta name="generator" content="Hexo 5.4.0"><meta name="theme" content="hexo-theme-yun"><title>OSPF | baiyun</title><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@900&amp;display=swap" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/star-markdown-css@0.1.25/dist/yun/yun-markdown.min.css"><script src="//at.alicdn.com/t/font_1140697_dxory92pb0h.js" async></script><script src="https://cdn.jsdelivr.net/npm/scrollreveal/dist/scrollreveal.min.js" defer></script><script>document.addEventListener("DOMContentLoaded", () => {
  [".post-card",".post-content img"].forEach((target)=> {
    ScrollReveal().reveal(target);
  })
});
</script><link rel="icon" href="/img/favicon.ico"><link rel="mask-icon" href="/img/favicon.ico" color="#ff4004"><link rel="alternate icon" href="/yun.ico"><link rel="preload" href="/css/hexo-theme-yun.css" as="style"><link rel="preload" href="/js/utils.js" as="script"><link rel="preload" href="/js/hexo-theme-yun.js" as="script"><link rel="prefetch" href="/js/sidebar.js" as="script"><link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin><script id="yun-config">
    const Yun = window.Yun || {};
    window.CONFIG = {"hostname":"baiyun067.gitee.io","root":"/","title":"白云21世纪数字一号亭","version":"1.6.2","mode":"auto","copycode":true,"page":{"isPost":true},"i18n":{"placeholder":"搜索...","empty":"找不到您查询的内容: ${query}","hits":"找到 ${hits} 条结果","hits_time":"找到 ${hits} 条结果（用时 ${time} 毫秒）"},"anonymous_image":"https://cdn.jsdelivr.net/gh/YunYouJun/cdn/img/avatar/none.jpg","say":{"api":"https://v1.hitokoto.cn","hitokoto":true},"fireworks":{"colors":["153, 153, 255","255, 255, 153","255, 64, 4","231, 145, 87","189, 225, 255","12, 202, 192"]}};
  </script><link rel="stylesheet" href="/css/hexo-theme-yun.css"><script src="/js/utils.js"></script><script src="/js/hexo-theme-yun.js"></script><meta name="description" content="OSPF （Open Shortest Path First）由IETF定义 ​                内部网关路由协议 IGP  ​                外部网关路由协议 EGP         每一台运行了OSPF的路由器都要了解整个网络链路状态信息，  LSA（Link State Advertisement    链路状态信息）:包含了路由器已知的接口IP地址、掩码、开销">
<meta property="og:type" content="article">
<meta property="og:title" content="OSPF">
<meta property="og:url" content="https://baiyun067.gitee.io/2021/11/05/OSPF/index.html">
<meta property="og:site_name" content="baiyun">
<meta property="og:description" content="OSPF （Open Shortest Path First）由IETF定义 ​                内部网关路由协议 IGP  ​                外部网关路由协议 EGP         每一台运行了OSPF的路由器都要了解整个网络链路状态信息，  LSA（Link State Advertisement    链路状态信息）:包含了路由器已知的接口IP地址、掩码、开销">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://baiyun067.gitee.io/images/OSPF/01.png">
<meta property="og:image" content="https://baiyun067.gitee.io/images/OSPF/02.png">
<meta property="og:image" content="https://baiyun067.gitee.io/images/OSPF/03.png">
<meta property="article:published_time" content="2021-11-05T02:21:22.000Z">
<meta property="article:modified_time" content="2021-11-19T08:13:28.172Z">
<meta property="article:author" content="baiyun">
<meta property="article:tag" content="数通笔记">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://baiyun067.gitee.io/images/OSPF/01.png"><script src="/js/ui/mode.js"></script></head><body><script defer src="https://cdn.jsdelivr.net/npm/animejs@latest"></script><script defer src="/js/ui/fireworks.js"></script><canvas class="fireworks"></canvas><div class="container"><a class="sidebar-toggle hty-icon-button" id="menu-btn"><div class="hamburger hamburger--spin" type="button"><span class="hamburger-box"><span class="hamburger-inner"></span></span></div></a><div class="sidebar-toggle sidebar-overlay"></div><aside class="sidebar"><script src="/js/sidebar.js"></script><ul class="sidebar-nav"><li class="sidebar-nav-item sidebar-nav-toc hty-icon-button" data-target="post-toc-wrap" title="文章目录"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-list-ordered"></use></svg></li><li class="sidebar-nav-item sidebar-nav-overview hty-icon-button sidebar-nav-active" data-target="site-overview-wrap" title="站点概览"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-passport-line"></use></svg></li></ul><div class="sidebar-panel sidebar-panel-active" id="site-overview-wrap"><div class="site-info fix-top"><a class="site-author-avatar" href="/about/" title="baiyun"><img width="96" loading="lazy" src="/img/avatar.png" alt="baiyun"></a><div class="site-author-name"><a href="/about/">baiyun</a></div><span class="site-name">baiyun</span><sub class="site-subtitle"></sub><div class="site-desciption"></div></div><nav class="site-state"><a class="site-state-item hty-icon-button icon-home" href="/" title="首页"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-home-4-line"></use></svg></span></a><div class="site-state-item"><a href="/archives/" title="归档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-archive-line"></use></svg></span><span class="site-state-item-count">8</span></a></div><div class="site-state-item"><a href="/categories/" title="分类"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-folder-2-line"></use></svg></span><span class="site-state-item-count">0</span></a></div><div class="site-state-item"><a href="/tags/" title="标签"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="site-state-item-count">3</span></a></div><a class="site-state-item hty-icon-button" target="_blank" rel="noopener" href="https://yun.yunyoujun.cn" title="文档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-settings-line"></use></svg></span></a></nav><hr style="margin-bottom:0.5rem"><div class="links-of-author"><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://github.com/orgojourney" title="GitHub" target="_blank" style="color:#6e5494"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-github-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://space.bilibili.com/274272715" title="哔哩哔哩" target="_blank" style="color:#FF8EB3"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-bilibili-line"></use></svg></a></div><hr style="margin:0.5rem 1rem"><div class="links"><a class="links-item hty-icon-button" href="/links/" title="我的小伙伴们" style="color:dodgerblue"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-genderless-line"></use></svg></a></div><br><a class="links-item hty-icon-button" id="toggle-mode-btn" href="javascript:;" title="Mode" style="color: #f1cb64"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-contrast-2-line"></use></svg></a></div><div class="sidebar-panel" id="post-toc-wrap"><div class="post-toc"><div class="post-toc-content">此文章未包含目录</div></div></div></aside><main class="sidebar-translate" id="content"><div id="post"><article class="hty-card post-block" itemscope itemtype="https://schema.org/Article"><link itemprop="mainEntityOfPage" href="https://baiyun067.gitee.io/2021/11/05/OSPF/"><span hidden itemprop="author" itemscope itemtype="https://schema.org/Person"><meta itemprop="name" content="baiyun"><meta itemprop="description"></span><span hidden itemprop="publisher" itemscope itemtype="https://schema.org/Organization"><meta itemprop="name" content="baiyun"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">OSPF</h1><div class="post-meta"><div class="post-time" style="display:inline-block"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-calendar-line"></use></svg></span> <time title="创建时间：2021-11-05 10:21:22" itemprop="dateCreated datePublished" datetime="2021-11-05T10:21:22+08:00">2021-11-05</time><span class="post-meta-divider">-</span><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-calendar-2-line"></use></svg></span> <time title="修改时间：2021-11-19 16:13:28" itemprop="dateModified" datetime="2021-11-19T16:13:28+08:00">2021-11-19</time></div><div class="post-classify"><span class="post-tag"><a class="tag-item" href="/tags/%E6%95%B0%E9%80%9A%E7%AC%94%E8%AE%B0/" style="--text-color:var(--hty-text-color)"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="tag-name">数通笔记</span></a></span></div></div></header><section class="post-body" itemprop="articleBody"><div class="post-content markdown-body" style="--smc-primary:#ff4004;"><p><strong>OSPF</strong> （Open Shortest Path First）由IETF定义</p>
<p>​                内部网关路由协议 IGP </p>
<p>​                外部网关路由协议 EGP</p>
<img src="/images/OSPF/01.png"/ loading="lazy">







<p style="font-size: 10px;">每一台运行了OSPF的路由器都要了解整个网络链路状态信息，</p>

<p><strong>LSA</strong>（Link State Advertisement    链路状态信息）:包含了路由器已知的接口IP地址、掩码、开销和网络类型等信息</p>
<p>收到LSA的路由器都可以根据LSA提供的信息建立自己的链路状态数据库<strong>LSDB</strong>（Link State Database）并在LSDB的基础上使用SPF算法进行运算，建立起到达每个网络的最短路径树。最后，通过最短路径树得出到达目的网络的最优路由，并将其加入到IP路由表中。</p>
<p><strong>收到LSA的路由器，构建区域内完整路由结构</strong></p>
<img src="/images/OSPF/02.png"/ loading="lazy">



<p>OSPF直接运行在IP协议之上，使用IP协议号89。</p>
<p>OSPF有五种报文类型，每种报文都使用相同的OSPF报文头。</p>
<p>1、<strong>Hello报文</strong>：<strong>最常用的一种报文，用于发现、维护邻居关系</strong>。并在广播和NBMA（None-Broadcast Multi-Access）类型的网络中选举指定路由器DR（Designated Router）和备份指定路由器BDR（Backup Designated Router）。</p>
<p>2、<strong>DD报文</strong>：两台路由器进行LSDB数据库同步时，用DD报文来<strong>描述自己的LSDB</strong>。DD报文的内容包括LSDB中每一条LSA的头部（LSA的头部可以唯一标识一条LSA）。LSA头部只占一条LSA的整个数据量的一小部分，所以，这样就可以减少路由器之间的协议报文流量。</p>
<p>3、<strong>LSR报文</strong>：两台路由器互相交换过DD报文之后，知道对端的路由器有哪些LSA是本地LSDB所缺少的，这时需要<strong>发送LSR报文向对方请求缺少的LSA</strong>，LSR只包含了所需要的LSA的摘要信息。</p>
<p>4、<strong>LSU报文</strong>：用来向对端路由器发送所需要的LSA。</p>
<p>5、<strong>LSACK报文</strong>：用来对接收到的LSU报文进行确认。</p>
<img src="/images/OSPF/03.png"/ loading="lazy">

<p><strong>建立邻居关系过程：</strong></p>
<p>​        <strong>Down</strong>：这是邻居的初始状态，表示没有在邻居失效时间间隔内收到来自邻居路由器的Hello数据包。</p>
<p>​        <strong>Attempt</strong>：此状态只在NBMA网络上存在，表示没有收到邻居的任何信息，但是已经周期性的向邻居发送报文，发送间隔为HelloInterval。如果RouterDeadInterval间隔内未收到邻居的Hello报文，则转为Down状态。</p>
<p>​        <strong>Init</strong>：在此状态下，路由器已经从邻居收到了Hello报文，但是自己不在所收到的Hello报文的邻居列表中，尚未与邻居建立双向通信关系。</p>
<p>​        <strong>2-Way</strong>：在此状态下，双向通信已经建立，但是没有与邻居建立邻接关系。这是建立邻接关系以前的最高级状态。</p>
<p>​        <strong>ExStart</strong>：这是形成邻接关系的第一个步骤，邻居状态变成此状态以后，路由器开始向邻居发送DD报文。主从关系是在此状态下形成的，初始DD序列号也是在此状态下决定的。在此状态下发送的DD报文不包含链路状态描述。</p>
<p>​        <strong>Exchange</strong>：此状态下路由器相互发送包含链路状态信息摘要的DD报文，描述本地LSDB的内容。</p>
<p>​        <strong>Loading</strong>：相互发送LSR报文请求LSA，发送LSU报文通告LSA。</p>
<p>​        <strong>Full</strong>：路由器的LSDB已经同步。</p>
<p style="color:red;">注：只有Two-Way和Full是稳定状态</p>





<p>路由写出接口，设备会认为是直连，发包时首先发送arp，arp目标ip填写的是数据包的目标ip</p>
<p>比如ping 6.6.6.6 直连是 1.0.0.2，arp的目标是6.6.6.6，若非开启代理arp则超时</p>
<p>流策略</p>
<p>acl 3000<br>rule 5 permit ip source 2.0.0.0 0.0.0.255 dest 7.7.7.7 0.0.0.0<br>traffic classifier shiyan<br>if-match acl 3000<br>traffic behavior shiyan<br>deny<br>traffic policy shiyan<br>classifier shiyan behavior shiyan</p>
<p>traffic classifier shiyan <strong>创建流分类</strong></p>
<p>traffic behavvior shiyan2 <strong>创建流行为</strong></p>
<p>traffic policy shiyan3 <strong>创建流策略</strong></p>
<p>traffic-policy shiyan3 inbound <strong>调用流策略</strong></p>
<p>dis traffic-policy addlied-record <strong>查看</strong></p>
<p><strong>未完结待更新</strong></p>
</div><div id="reward-container"><span class="hty-icon-button button-glow" id="reward-button" title="打赏" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === &quot;none&quot;) ? &quot;block&quot; : &quot;none&quot;;"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-hand-coin-line"></use></svg></span><div id="reward-comment">雀浅花工作室(｡･◁･｡)ﾉ✡.</div><div id="qr" style="display:none;"><div style="display:inline-block"><a href="/img/alreward.png"><img loading="lazy" src="/img/alreward.png" alt="支付宝" title="支付宝"></a><div><span style="color:#00A3EE"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-alipay-line"></use></svg></span></div></div><div style="display:inline-block"><a href="/img/qqreward.png"><img loading="lazy" src="/img/qqreward.png" alt="QQ 支付" title="QQ 支付"></a><div><span style="color:#12B7F5"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-qq-line"></use></svg></span></div></div><div style="display:inline-block"><a href="/img/wxreward.png"><img loading="lazy" src="/img/wxreward.png" alt="微信支付" title="微信支付"></a><div><span style="color:#2DC100"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-wechat-pay-line"></use></svg></span></div></div></div></div><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者：</strong>baiyun</li><li class="post-copyright-link"><strong>本文链接：</strong><a href="https://baiyun067.gitee.io/2021/11/05/OSPF/" title="OSPF">https://baiyun067.gitee.io/2021/11/05/OSPF/</a></li><li class="post-copyright-license"><strong>版权声明：</strong>本博客所有文章除特别声明外，均默认采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="noopener" title="CC BY-NC-SA 4.0 "><svg class="icon"><use xlink:href="#icon-creative-commons-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-by-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-nc-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-sa-line"></use></svg></a> 许可协议。</li></ul></section></article><div class="post-nav"><div class="post-nav-item"><a class="post-nav-prev" href="/2021/11/17/BGP/" rel="prev" title="BGP"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-left-s-line"></use></svg><span class="post-nav-text">BGP</span></a></div><div class="post-nav-item"><a class="post-nav-next" href="/2021/10/12/xshell%E7%AD%89%E5%AE%A2%E6%88%B7%E7%AB%AF-telnet-%E8%BF%9E%E6%8E%A5ensp%E8%B7%AF%E7%94%B1%E5%99%A8/" rel="next" title="xshell等客户端 telnet 连接ensp路由器"><span class="post-nav-text">xshell等客户端 telnet 连接ensp路由器</span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-right-s-line"></use></svg></a></div></div></div><div class="hty-card" id="comment"><div class="comment-tooltip text-center"><span>要不要和我说些什么？</span><br></div></div></main><footer class="sidebar-translate" id="footer"><div class="copyright"><span>&copy; 2019 – 2021 </span><span class="with-love" id="animate"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-cloud-line"></use></svg></span><span class="author"> baiyun</span></div><div class="powered"><span>由 <a href="https://hexo.io" target="_blank" rel="noopener">Hexo</a> 驱动 v5.4.0</span><span class="footer-separator">|</span><span>主题 - <a rel="noopener" href="https://github.com/YunYouJun/hexo-theme-yun" target="_blank"><span>Yun</span></a> v1.6.2</span></div></footer><a class="hty-icon-button" id="back-to-top" aria-label="back-to-top" href="#"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-up-s-line"></use></svg><svg class="progress-circle-container" viewBox="0 0 100 100"><circle class="progress-circle" id="progressCircle" cx="50" cy="50" r="48" fill="none" stroke="#ff4004" stroke-width="2" stroke-linecap="round"></circle></svg></a></div></body></html>